var pageFoot = {
    PageUrl: "",
    PageIndex: 1,
    Count: 0,
    PageNum: 0,
    BeginIndex: 1,
    EndIndex: 1,
    searchUrl:"",
    init: function () {
        pageFoot.PageUrl="";
        pageFoot.InitParam();
        pageFoot.InitPage();
        $("#DataTables_Table_0_first").on('click', function () { pageFoot.First() });
        $("#DataTables_Table_0_last").on('click', function () { pageFoot.Last() });
        $("#DataTables_Table_0_previous").on('click', function () { pageFoot.Before() });
        $("#DataTables_Table_0_next").on('click', function () { pageFoot.Next() });
    },
    Before: function () {
        pageFoot.PageIndex--;
        if (pageFoot.PageIndex < 1) {
            pageFoot.PageIndex = 0;
        }
        pageFoot.Go(pageFoot.PageIndex);
    },
    Next: function () {
        pageFoot.PageIndex++;
        if (pageFoot.PageIndex >= pageFoot.PageNum) {
            pageFoot.PageIndex = pageFoot.PageNum-1;
        }
        pageFoot.Go(pageFoot.PageIndex);
    },
    First: function () {
        pageFoot.Go(0);
    },
    Last: function () {
        pageFoot.Go(pageFoot.PageNum-1);
    },
    Jump: function () {
        pageFoot.PageIndex = parseInt($("#pagenum").val())-1;
        pageFoot.PageIndex = pageFoot.PageIndex < 1 ? 1 : pageFoot.PageIndex;
        pageFoot.PageIndex = pageFoot.PageIndex > pageFoot.PageNum ? pageFoot.PageNum : pageFoot.PageIndex;
        pageFoot.Go(pageFoot.PageIndex);
    },
    InitPage: function () {
        var html = '<li class="paginate_button previous" ><a href="javascript:;" aria-controls="datatable-checkbox" id="DataTables_Table_0_first" data-dt-idx="0" tabindex="0">首页</a></li>';
	    html+='<li class="paginate_button previous" ><a href="#" aria-controls="datatable-checkbox" id="DataTables_Table_0_previous" data-dt-idx="0" tabindex="0">上翻</a></li>';
        var currentClass = "on";
        var footBegin = pageFoot.BeginIndex;
        var footEnd = pageFoot.EndIndex;
        if(pageFoot.EndIndex>5){//页码总数大于5
        		if((pageFoot.PageIndex-pageFoot.BeginIndex)<2){
        			footEnd = 5;
        		}else if(pageFoot.EndIndex - pageFoot.PageIndex<=2){
        			footBegin = pageFoot.EndIndex - 4;
        		}else{
        			footBegin = pageFoot.PageIndex - 1;
        			footEnd = pageFoot.PageIndex + 3;
        		}
        }
        for (var i = footBegin; i <= footEnd; i++) {
            currentClass = '';
            if (pageFoot.PageIndex == (i-1)) {
                currentClass = ' active';
            }
            html+='<li class="paginate_button  '+currentClass+'"><a href="#" aria-controls="datatable-checkbox"  tabindex="'+(i-1)+'" onclick="pageFoot.Go('+(i-1)+')" >'+(i)+'</a></li>';
        }
        var goMoreNext = (pageFoot.EndIndex-(pageFoot.PageIndex+10))>0?(pageFoot.PageIndex+10):(pageFoot.EndIndex-1);
        if(pageFoot.EndIndex>5) html+='<li class="paginate_button next"><a href="#" aria-controls="datatable-checkbox" onclick="pageFoot.Go('+(goMoreNext)+')" data-dt-idx="2" tabindex="0">...</a></li>';
        html+='<li class="paginate_button next" ><a href="#" aria-controls="datatable-checkbox" id="DataTables_Table_0_next" data-dt-idx="2" tabindex="0">下翻</a></li>';
        html+='<li class="paginate_button previous"><a href="#" aria-controls="datatable-checkbox" id="DataTables_Table_0_last" data-dt-idx="0" tabindex="0">末页</a></li>';
        if(pageFoot.EndIndex>5) html+='<li class="paginate_button previous"><div class="col-md-1 col-sm-12 col-xs-12 form-group"><input type="text" id="pagenum" style="height:28px;margin-top:2px;width:28px"></div><a href="#" aria-controls="datatable-checkbox" data-dt-idx="0" onclick="pageFoot.Jump()" tabindex="0">跳</a></li>';
        
        $("#pageinfolist").html(html);
    },
    InitParam:function(){
        pageFoot.BeginIndex = parseInt(pageFoot.BeginIndex);
        pageFoot.EndIndex = parseInt(pageFoot.EndIndex);
        pageFoot.PageIndex = parseInt(pageFoot.PageIndex);
        pageFoot.PageNum = parseInt(pageFoot.PageNum);
        pageFoot.Count = parseInt(pageFoot.Count);
    },
    Go: function (index) {
        index=index+'';
        location.href = pageFoot.InitUrl(index);
    },
    InitUrl: function (index) {
        pageFoot.searchUrl = pageFoot.getCurrentUrl();
        return pageFoot.addParam("page",index).searchUrl;
    },
    addParam:function(key,value){
      if (value != 'undefined' && value != undefined && value != null && value.length > 0) {
          if (pageFoot.searchUrl.indexOf('?') > -1) {
              pageFoot.searchUrl += "&" + key + "=" + value;
          } else {
              pageFoot.searchUrl += "?" + key + "=" + value;
          }
      }
      return pageFoot;
    },
    getCurrentUrl:function(){

    },

}
function jump() {
    pageFoot.Jump();
}
